<?php

namespace api\modules\v1\controllers\marketing;

use Yii;
use api\controllers\OnAuthController;
use common\models\marketing\EffectType;
use common\helpers\CommonHelper;

/**
 * Class EffectTypeController
 * @package api\modules\v1\controllers\marketing
 */
class EffectTypeController extends OnAuthController
{
    /**
     * @var EffectType
     */
    public $modelClass = EffectType::class;

    /**
     * @api {get} /v1/marketing/effect-type/index 效果类型列表
     * @apiName index
     * @apiGroup EffectType
     *
     */
    public function actionIndexEffectType()
    {
        $projectId = $this->projectId;

        // 查询结果
        $data = Yii::$app->services->marketingEffectType->getList($projectId);

        return $data;
    }

    /**
     * @api {post} /v1/marketing/effect-type/create 新增效果类型
     * @apiName create
     * @apiGroup EffectType
     *
     * @apiParam {String} name              效果类型名称
     * @apiParam {Number} status            【1启用、0停用】
     */
    public function actionCreateEffectType()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;

        return Yii::$app->services->marketingEffectType->create($params);
    }

    /**
     * @api {post} /v1/marketing/effect-type/update 编辑效果类型
     * @apiName update
     * @apiGroup EffectType
     *
     * @apiParam {Number} id                效果类型ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateEffectType()
    {
        $params = Yii::$app->request->post();
        $params['member_id'] = Yii::$app->user->identity->member_id;
        $params['project_id'] = $this->projectId;
        return Yii::$app->services->marketingEffectType->update($params);
    }


    /**
     * @api {post} /v1/marketing/effect-type/update-status 编辑效果类型的状态
     * @apiName update-status
     * @apiGroup EffectType
     *
     * @apiParam {Number} id                效果类型ID
     * @apiParam {Number} status            状态【0停用 1启用】
     */
    public function actionUpdateEffectTypeStatus()
    {
        $id = Yii::$app->request->post('id');
        $status = Yii::$app->request->post('status');

        return Yii::$app->services->marketingEffectType->updateStatus($id, $status);
    }

    /**
     * @api {post} /v1/marketing/effect-type/delete 删除效果类型
     * @apiName delete
     * @apiGroup EffectType
     *
     * @apiParam {Number} id                效果类型ID
     */
    public function actionDeleteEffectType()
    {
        $id = Yii::$app->request->post('id');

        return Yii::$app->services->marketingEffectType->delete($id);
    }

    /**
     * @api {post} /v1/marketing/effect-type/true-delete 删除效果类型
     * @apiName delete
     * @apiGroup EffectType
     *
     * @apiParam {Number} id                效果类型ID
     */
    public function actionTrueDeleteEffectType()
    {
        $id = Yii::$app->request->post('id');
        return Yii::$app->services->marketingEffectType->trueDelete($id);
    }


}